import json


file_name = 'favorite_number.json'
try:
    # 如果已经储存数字，则打印消息
    with open(file_name) as file_obj:
        favorite_number = json.load(file_obj)
        print('I know your favorite number! It is ' +
              str(favorite_number) + '.')
except FileNotFoundError:
    # 如果未储存数字，则输入并储存
    with open(file_name, 'w') as file_obj:
        favorite_number = int(input('Enter your favorite number: '))
        json.dump(favorite_number, file_obj)
